package org.pps.gl.client.vue;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.HasVerticalAlignment;

/**
 * Réglages possibles pour un admin
 * 
 */
public class ADM_Reglages extends Composite {

	public ADM_Reglages(String mail) {
		final DialogBox reglages = new DialogBox();
		
		reglages.setText("Administration de Polytech +");
		
		FlexTable flexTable = new FlexTable();
		flexTable.setCellSpacing(5);
		flexTable.setCellPadding(5);
		flexTable.setSize("235px", "55px");
		
		Label lblTitre1 = new Label("Changer les pondérations");
		flexTable.setWidget(0, 0, lblTitre1);
		
		VerticalPanel ponderations = new VerticalPanel();
		flexTable.setWidget(1, 0, ponderations);
		ponderations.setSize("100%", "100%");
		
		HorizontalPanel contact = new HorizontalPanel();
		ponderations.add(contact);
		contact.setSize("100%", "20px");
		Label contactLabel = new Label("Contact");
		contact.add(contactLabel);
		contact.setCellVerticalAlignment(contactLabel, HasVerticalAlignment.ALIGN_MIDDLE);
		ListBox contactPond = new ListBox();
		contact.add(contactPond);
		contact.setCellHorizontalAlignment(contactPond, HasHorizontalAlignment.ALIGN_RIGHT);
		for (Integer i=0; i<10; i++)
			contactPond.addItem(i.toString());
		
		HorizontalPanel etude = new HorizontalPanel();
		ponderations.add(etude);
		etude.setSize("100%", "20px");
		Label etudeLabel = new Label("Etude");
		etude.add(etudeLabel);
		etude.setCellVerticalAlignment(contactLabel, HasVerticalAlignment.ALIGN_MIDDLE);
		ListBox etudePond = new ListBox();
		etude.add(etudePond);
		etude.setCellHorizontalAlignment(contactPond, HasHorizontalAlignment.ALIGN_RIGHT);
		for (Integer i=0; i<10; i++)
			etudePond.addItem(i.toString());
		
		HorizontalPanel experience = new HorizontalPanel();
		ponderations.add(experience);
		experience.setSize("100%", "20px");
		Label experienceLabel = new Label("Expérience");
		experience.add(experienceLabel);
		experience.setCellVerticalAlignment(contactLabel, HasVerticalAlignment.ALIGN_MIDDLE);
		ListBox experiencePond = new ListBox();
		experience.add(experiencePond);
		experience.setCellHorizontalAlignment(contactPond, HasHorizontalAlignment.ALIGN_RIGHT);
		for (Integer i=0; i<10; i++)
			experiencePond.addItem(i.toString());
		
		Button btnModif = new Button("Modifer");
		flexTable.setWidget(1, 1, btnModif);
		btnModif.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				//TODO changer les pondérations de la recherche par les valeurs choisies
				reglages.hide();
			}
		});
		
		Label lblTitre2 = new Label("Supprimer un compte");
		flexTable.setWidget(2, 0, lblTitre2);
		
		final PasswordTextBox textBox2 = new PasswordTextBox();
		flexTable.setWidget(3, 0, textBox2);
		textBox2.setSize("210px", "20px");
		
		Button btnSuppr = new Button("Désinscription");
		btnSuppr.setText("Suppression");
		flexTable.setWidget(3, 1, btnSuppr);
		btnSuppr.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				//TODO supprimer le compte correspondant au mail choisi
				reglages.hide();
			}
		});

		Button fermer = new Button("Fermer");
		flexTable.setWidget(4, 0, fermer);
		// pour fermer
		fermer.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				reglages.hide();
			}
		});
		
		reglages.setWidget(flexTable);
		flexTable.getCellFormatter().setHorizontalAlignment(4, 0, HasHorizontalAlignment.ALIGN_CENTER);
		reglages.setAnimationEnabled(true);

		Label b = new Label(mail);
		b.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				reglages.center();
			}
		});
		initWidget(b);
	}
}
